package code.starivan.niuke.jianoffer;

import java.util.ArrayList;
import java.util.Collections;

/**
 * Created by Ivan on 2015/8/26.
 */
public class DynamicArray {
    private ArrayList<Integer> list=new ArrayList<>();
    public void Insert(Integer num) {
        list.add(num);
        Collections.sort(list);
    }

    public Double GetMedian() {
        if(list.size()==0){
            return 0.0;
        }

        int mid=list.size()/2;
        if((list.size()%2)==0){
            return ((double)list.get(mid)+(double)list.get(mid-1))/2.0;
        }else{
            return (double)list.get(mid);
        }
    }
}
